package com.message.tcp.ip.ui.transaction.dialog;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.util.List;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.message.tcp.ip.socket.configure.entity.Case;
import com.message.tcp.ip.socket.configure.service.CaseService;
import com.message.tcp.ip.ui.transaction.action.AddReqTransDe;

public class RequestPane extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JTextField txtReq;
	private JTable table;
	private JPanel panel;
	private JLabel mtiLabel;
	private JComboBox<String> mtiBox;
	private JLabel tagLabel;
	private JLabel txnLabel;
	private JComboBox<String> txnCodeBox;
	private JButton saveButton;
	private JButton addButton;
	private JButton deleteButton;
	private JScrollPane scrollPane;
	private CaseService caseService;
	/**
	 * Create the panel.
	 */
	public RequestPane() {
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		caseService = (CaseService) context.getBean("caseService");
		setLayout(new BorderLayout(0, 0));
		panel = new JPanel();
		panel.setLayout(new FlowLayout());
		mtiLabel = new JLabel("MTI");
		String[] mtiList = {"0800","0200","0420"};
		mtiBox = new JComboBox<String>(mtiList);
		tagLabel = new JLabel("TAG");
		txtReq = new JTextField();
		txnLabel = new JLabel("TxnCode");
		List<Case> cases = caseService.getAcqCases();
		String[] list = new String[cases.size()];
		int i = 0;
		for(Case c : cases){
			list[i++] = c.getCode();
		}
		DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>(list);
		txnCodeBox = new JComboBox<String>(model);
		saveButton = new JButton("save");
		addButton = new JButton("add");
		deleteButton = new JButton("delete");
		String[] columnName = { "DE","FLAG", "VALUE", "PATTERN" };
		Object[][] data = null;
		DefaultTableModel columnModel = new DefaultTableModel(data, columnName);
		table = new JTable(columnModel);
		txtReq.setColumns(10);
		txtReq.setEditable(false);
		txtReq.setText("REQ");
		
		panel.add(tagLabel);
		panel.add(txtReq);
		panel.add(mtiLabel);
		panel.add(mtiBox);
		panel.add(txnLabel);
		panel.add(txnCodeBox);
		panel.add(saveButton);
		panel.add(addButton);
		panel.add(deleteButton);
		scrollPane = new JScrollPane(table);
		
		add(panel, BorderLayout.NORTH);
		add(scrollPane, BorderLayout.CENTER);
		// add action
		addButton.addActionListener(new AddReqTransDe(table));
	}
	
}
